Skip to content

Make tensorflow optional in requirements - #5086

Open
aireenmei wants to merge 1 commit into
mainfrom
aireen/remove_tf
Open

Make tensorflow optional in requirements#5086
aireenmei wants to merge 1 commit into
mainfrom
aireen/remove_tf

Conversation

@aireenmei

@aireenmei aireenmei commented Sep 1, 2026

Copy link
Copy Markdown
Collaborator

Description

Summary

Makes tensorflow, tensorflow-datasets, tensorflow-text, Jetstream and seqio optional dependencies in MaxText (Jetstream pulls tensorflow through Jetstream -> seqio_tensorflow-text -> tensorflow). Core pre-training lock files are now TensorFlow-free, while users requiring legacy TFDS pipelines or JetStream serving can install optional dependencies via --with-tf.

b/555209521

Changes

  • Requirements & Lock Files:
    • Removed TensorFlow, TFDS, TF-Text, and SeqIO from base requirements and generated lock files (tpu-requirements.txt, cuda12-requirements.txt, decoupled-requirements.txt).
    • Added src/dependencies/extra_deps/tf_requirements.txt and jetstream_github_deps.txt for optional installation.
  • Installation & Setup:
    • Added --with-tf flag (and WITH_TF env var) to install_pre_train_extra_deps.py to install optional TensorFlow and JetStream dependencies.
    • Added TF option to src/dependencies/scripts/setup.sh and docker_build_dependency_image.sh (defaults to false).
    • Added ARG TF=true to Dockerfiles because nightly image workflow does not pass "TF" in build arg yet, will keep TF in nightly images until we build separated workflow for TF and no-TF images.
  • JetStream Stubs & Tests:
    • Updated gcloud_stub.py to return stubs when JetStream or its dependencies are absent, avoiding import crashes.
    • Added skip guards to JetStream-dependent tests (inference_microbenchmark_smoke_test.py, offline_engine_test.py). The following tests are skipped in the no-TF environment. Will follow up with a dedicated jetstream CI workflow for these tests similar to the vllm post-training CI workflow.
    * `tests/integration/smoke/inference_microbenchmark_smoke_test.py`
    * `tests/unit/offline_engine_test.py`
    * `tests/integration/decode_tests.py`
    * `tests/integration/generate_param_only_checkpoint_test.py`
    * `tests/integration/maxengine_test.py`
    * `tests/unit/maxengine_nnx_test.py`
    * `tests/unit/deepseek_decode_consistency_test.py`
  • Added automatic JetStream checks to 42 end-to-end test scripts calling maxtext.inference.decode to install --with-tf if absent.
  • Documentation: Updated install_maxtext.md and data_input_tfds.md with --with-tf instructions.

Tests

  • github CI test pass (The failure in tests/unit/mmap_data_processing_test.py::GrainMmapNpyEvalConfigTest is at head and unrelated to this PR)
  • Generated environments following this instruction for cases with or without TF. Confirmed it works as expected.
uv pip install -e .[tpu] --resolution=lowest
install_tpu_pre_train_extra_deps  # tested with and without --with-tf
  • Tested generating tf and no-tf maxtext images, confirm reduced image size (local uncompressed size 5.95 GB -> 3.91 GB, 35% reduction)
bash src/dependencies/scripts/docker_build_dependency_image.sh DEVICE=tpu MODE=stable TF=true LOCAL_IMAGE_NAME=maxtext_tf
bash src/dependencies/scripts/docker_build_dependency_image.sh DEVICE=tpu MODE=stable TF=false LOCAL_IMAGE_NAME=maxtext_no_tf

Checklist

Before submitting this PR, please make sure (put X in square brackets):

  • I have performed a self-review of my code. For an optional AI review, add the gemini-review label.
  • I have necessary comments in my code, particularly in hard-to-understand areas.
  • I have run end-to-end tests tests and provided workload links above if applicable.
  • I have made or will make corresponding changes to the doc if needed, including adding new documentation pages to the relevant Table of Contents (toctree directive) as explained in our documentation.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request deprecates the legacy TFDS input pipeline in favor of the Grain pipeline and makes TensorFlow-related packages optional dependencies. It introduces a new tf_requirements.txt file and updates the installation scripts and documentation to support an optional --with-tf flag. Additionally, various generated requirements files are updated with bumped dependency versions. The review feedback recommends removing capture_output=True from the subprocess installation command to prevent the CLI from appearing hung, and suggests adding seqio to the optional TensorFlow requirements since it is needed for the legacy pipeline.

Comment thread src/dependencies/scripts/install_pre_train_extra_deps.py
Comment thread src/dependencies/extra_deps/tf_requirements.txt
@codecov

codecov Bot commented Sep 1, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 80.00000% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/maxtext/common/gcloud_stub.py 80.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@@ -1885,10 +1885,10 @@ def get_tokenizer(self) -> Any:
"""
token_params_is_stub = getattr(_token_params_ns, "_IS_STUB", False)
engine_api_is_stub = getattr(engine_api, "_IS_STUB", False)
if is_decoupled() and (token_params_is_stub or engine_api_is_stub):
if token_params_is_stub or engine_api_is_stub:

@aireenmei aireenmei Sep 3, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clarification: is_decoupled() is redundant here, token_params_is_stub or engine_api_is_stub is sufficient.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant